package portal.mybatis.dao.service;

import java.sql.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import portal.mybatis.dao.SockectLog;
import portal.mybatis.dao.mapper.SockectLogMapper;

@Service
public class SockectLogService {
	@Autowired
	SockectLogMapper sockectLogMapper;
	public boolean  updateByKeySelective(SockectLog log){
		if(log==null || log.getJobId()==null) return false;
		return sockectLogMapper.updateByKeySelective(log)>0;
	}
	public boolean insertSelective(SockectLog log){
		if(log==null || log.getJobId()==null) return false;
		return sockectLogMapper.insertSelective(log)>0;
	}
	public SockectLog selectByKey(SockectLog log){
		if(log==null || log.getJobId()==null)
			return null;
		List<SockectLog> list =sockectLogMapper.selectByPrimaryKey(log);
		if(list==null ||list.size()==0)
			return null;
		return list.get(0);
	}
	public boolean insertLog(String taskHash, String subTaskHash, String logFileUri, String algorithmState,
            String algorithmSchedule, String logLevel, String logMessage,String jobId){
		SockectLog log =new SockectLog(taskHash,subTaskHash,logFileUri,algorithmState,algorithmSchedule,logLevel,logMessage,jobId);
		return sockectLogMapper.insertSelective(log)>0;
	}
	public boolean updateByKeySelective(String jobId,String algorithmState,String logFileUri,String algorthmSchedule){
		return updateByKeySelective(jobId,algorithmState,logFileUri,new Date(System.currentTimeMillis()),algorthmSchedule);
	}
	public boolean updateByKeySelective(String jobId,String algorithmState,String logFileUri,Date time,String algorithSchedule){
		SockectLog log= new SockectLog(jobId,algorithmState,logFileUri,time,algorithSchedule);
		return this.sockectLogMapper.updateByKeySelective(log)>0;
	}
}
